import {
  createStore
} from 'vuex'
const user = createStore({
  state: () => ({
    address:JSON.parse(uni.getStorageSync('address') || '{}')
  }),
mutations: {
  // 存储 address 的方法
  updateAddress(state,address){
    // 把接收的address存储到仓库当中
    state.address = address
    // 本地存储地址
    this.commit('saveAddressToStorage');
  },
  // 将收货地址中的数据持久化存储到本地
  saveAddressToStorage(state) {
    uni.setStorageSync('address', JSON.stringify(state.address))
  },
},
getters: {
  addstr: state => {
    // 收货详细地址的计算属性
    if (!state.address.provinceName) return ''
    // 拼接 省，市，区，详细地址 的字符串并返回给用户
    return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
    }
}
})

export default user